$(document).ready(function(){
	NavGoTo();
	MouseAction();
	ShowUserName();
});
//导航栏跳转
function NavGoTo(){
	//首页跳转
	$("div.allhead_center_nav_item:eq(0)").click(function(){
		window.location.href = (basePath+"/index");
//		window.location.href = (basePath+"/rentrepay");
//		window.location.href = (basePath+"/linerepay");
//		window.location.href = (basePath+"/rentandservicerule");
//		window.location.href = (basePath+"/lineservicerule");
//		window.open(basePath+"/pctest");
//		window.location.href = (basePath+"/mycenter");
//		window.location.href = (basePath+"/my/testorderinfo");
//		window.location.href = (basePath+"/myorderlist");
	});
	//房车租赁跳转
	$("div.allhead_center_nav_item:eq(1)").click(function(){
		window.location.href = (basePath+"/rentindex");
	});
	//房车旅行跳转
	$("div.allhead_center_nav_item:eq(2)").click(function(){
		window.location.href = (basePath+"/myorderlist?type=myCenter");
	});
	//超级保障跳转
	$("div.allhead_center_nav_item:eq(3)").click(function(){
		window.location.href = (basePath+"/superinsurance");
	});
	//登录跳转
	$("div.allhead_top_login_login").click(function(){
		window.location.href = (basePath+"/loginstepone?loginstepflag=5");
	});
	//注册跳转
	$("div.allhead_top_login_register").click(function(){
		window.location.href = (basePath+"/myregister");
	});
	//订单查询中的全部订单跳转
	$("div.allhead_top_order_choose_item:eq(0)").click(function(){
		window.location.href = (basePath+"/myorderlist?type=0");
	});
	//订单查询中的房车租赁跳转
	$("div.allhead_top_order_choose_item:eq(1)").click(function(){
		window.location.href = (basePath+"/myorderlist?type=1");
	});
	//订单查询中的房车旅行跳转
	$("div.allhead_top_order_choose_item:eq(2)").click(function(){
		window.location.href = (basePath+"/myorderlist?type=2");
	});
	//网站导航中的房车租赁跳转
	$("div.allhead_top_nav_choose_item:eq(0)").click(function(){
		window.location.href = (basePath+"/rentindex");
	});
	//网站导航中的个人中心跳转
	$("div.allhead_top_nav_choose_item:eq(1)").click(function(){
		window.location.href = (basePath+"/mycenter");
	});
	//网站导航中的房车旅行跳转
	$("div.allhead_top_nav_choose_item:eq(2)").click(function(){
		window.location.href = (basePath+"/lineindex");
	});
	//网站导航中的超级保障跳转
	$("div.allhead_top_nav_choose_item:eq(3)").click(function(){
		window.location.href = (basePath+"/superinsurance");
	});
}
//鼠标移上去的时候隐藏显示的动作
function MouseAction(){
	//鼠标移至订单查询
	$("div.allhead_top_order_content").mouseover(function(){
		$("div.allhead_top_order_choose").css("display","block");
		$("div.allhead_top_order_choose").focus();
//		$("div.allhead_center_nav").fadeOut();
	});
	//鼠标从订单查询下面的选项挪开
	$("div.allhead_top_order_choose").mouseleave(function(){
		$("div.allhead_top_order_choose").css("display","none");
//		$("div.allhead_center_nav").fadeIn();
	});
	//鼠标挪至微信icon
	$("div.allhead_top_otherlogin_weixing").mouseover(function(){
		$("div.allhead_top_otherloginother").css("display","block");
//		$("div.allhead_center_nav").fadeOut();
//		$("div.allhead_top_order").css("display","none");
	});
	//鼠标挪开微信icon
	$("div.allhead_top_otherlogin_weixing").mouseleave(function(){
		$("div.allhead_top_otherloginother").css("display","none");
//		$("div.allhead_center_nav").fadeIn();
//		$("div.allhead_top_order").css("display","block");
	});
	//鼠标挪至网站导航
	$("div.allhead_top_nav_nav").mouseover(function(){
		$("div.allhead_top_nav_choose").css("display","block");
//		$("div.allhead_center_nav").fadeOut();
//		$("div.allhead_top_order").css("display","none");
	});
	//鼠标挪开网站导航
	$("div.allhead_top_nav_choose").mouseleave(function(){
		$(this).css("display","none");
//		$("div.allhead_center_nav").fadeIn();
//		$("div.allhead_top_order").css("display","block");
	});
	//鼠标挪进logo所在行时复原
	$("div.allhead_center").mouseenter(function(){
		$("div.allhead_center_nav").fadeIn();
		$("div.allhead_top_order_choose").css("display","none");
		$("div.allhead_top_otherloginother").css("display","none");
		$("div.allhead_top_nav_choose").css("display","none");
	});
	//点击微博打开外链
	$("div.allhead_top_otherlogin_weibo").click(function(){
		var url = "https://weibo.com/sofangche";
		window.open(url);
	});
}
//当token中有username的时候显示
function ShowUserName(){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/meb/checklogin",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			if(data.code == "1"){
				var name = data.data[0].name;
				$("div.allhead_top_usernamein").text(name);
				$("div.allhead_top_login").css("display","none");
				$("div.allhead_top_username").css("display","block");
			}else{
				var name = "";
				$("div.allhead_top_usernamein").text(name);
				$("div.allhead_top_login").css("display","block");
				$("div.allhead_top_username").css("display","none");
			}
			OutLogin();
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//退出登录
var OutLogin = function(){
	$("div.allhead_top_usernameout").click(function(){
		$.ajax({
			dataType : "json",
			type : "post",
			url : basePath+"/meb/loginout",
			data : {
				
			},
			contentType : "application/x-www-form-urlencoded;charset=utf-8",

			success : function(data) {
				console.log(data);
//				window.location.href = (basePath+"/index");
			},
			error : function() {
//				layer.msg("退出失败，请检查您的网络连接");
			},
			complete : function() {
				layer.msg("您已退出登录");
				window.location.href = (basePath+"/index");				
			},
		});
	});
	
}
